home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / util / libs / mufs_usergroup.lha / usergroup / make_fd.awk < prev    next >
Text File  |  1992-09-02  |  6KB  |  246 lines

  1. # Hey Emacs! This file might as well be -*- C -*-
  2. #
  3. # make_fd.awk -- create prototype, FD and pragma files
  4. #
  5. # Author: ppessi <Pekka.Pessi@hut.fi>
  6. #
  7. # Copyright ⌐ 1993, 1994 AmiTCP/IP Group, <AmiTCP-Group@hut.fi>
  8. #                   Helsinki University of Technology, Finland.
  9. #
  10. # Created      : Mon Nov 29 21:14:58 1993 ppessi
  11. # Last modified: Sat Feb 12 02:57:44 1994 ppessi
  12. #
  13. # $Id: make_fd.awk,v 1.4 1994/02/17 02:23:05 ppessi Exp $
  14. #
  15. # $Log: make_fd.awk,v $
  16. # Revision 1.4  1994/02/17  02:23:05  ppessi
  17. # Changed the defines for include files
  18. #
  19. # Revision 1.3  1994/01/21  08:32:32  ppessi
  20. # Added a "what" variable to determine the conversion result
  21. #
  22. # Revision 1.2  1994/01/21  05:00:16  ppessi
  23. # Fancier blurbs.
  24. #
  25. #
  26.  
  27. # Each prototype must in the form
  28. # ASM type name(REG(rn) type name);
  29. # Do not forget argument name!
  30. # The tagcall stub must be given in the next line of 
  31. # /* TAGCALL tag_call_stub_name */
  32. #
  33.  
  34. BEGIN {
  35.   stderr = "console:";
  36.  
  37.   if (what != "protos" && what != "pragmas" && what != "fd") {
  38.     print "but what to do?" > stderr;
  39.     exit(10);
  40.   }
  41.  
  42.   library = "usergroup";
  43.   basename = "UserGroupBase";
  44.   fds = "fd/"library"_lib.fd";
  45.   pragmaname = "pragmas/"library"_pragmas.h"
  46.   pragmas = "include/"pragmaname;
  47.   outputname = "clib/"library"_protos.h";
  48.   define = toupper(outputname);
  49.   gsub("[/.]", "_", define);
  50.   output = "include/"outputname;
  51.  
  52.   libprefix = "^R_";
  53.   libfunctype = "^ASM$";
  54.  
  55.   libincludename = "libraries/"library".h";
  56.   libincludedefine = toupper(libincludename);
  57.   gsub("[/.]", "_", libincludedefine);
  58.   libinclude = "include/"libincludename;
  59.  
  60.   libincludename1 = "pwd.h";
  61.   libincludedefine1 = toupper(libincludename1);
  62.   gsub("[/.]", "_", libincludedefine1);
  63.  
  64.   libincludename2 = "grp.h";
  65.   libincludedefine2 = toupper(libincludename2);
  66.   gsub("[/.]", "_", libincludedefine2);
  67.  
  68.   copyright = \
  69.     "**\tCopyright (c) 1993 AmiTCP/IP Group, <AmiTCP-Group@hut.fi>\n"\
  70.     "**\t    Helsinki University of Technology, Finland.\n"\
  71.     "**\t    All rights reserved.\n";
  72.  
  73.   state = 0;
  74.   priv = 1;
  75.   public = 2;
  76.  
  77.   release="$Release$";
  78.   rcsdate="$Date: 1994/02/17 02:23:05 $";
  79. }
  80.  
  81. state == 0 && $0 ~ /\$Date/ {
  82.   rcsdate = $0;
  83.   sub(/^[^$]*/, "", rcsdate);
  84.   sub(/[^$]*$/, "", rcsdate); 
  85. }
  86.  
  87. state == 0 && $0 ~ /\$Revision/ {
  88.   rcsid = $0;
  89.   sub(/^[^$]*/, "", rcsid);
  90.   sub(/[^$]*$/, "", rcsid); 
  91.  
  92.   fnfmt = "**\t$Filename: %s $\n";
  93.   rcsfmt = "**\t%s\n";
  94.   
  95.   if (what == "protos") {
  96.     protosblurb="**\n**\tC prototypes for %s.library\n**\n";
  97.     printf("#ifndef %s\n", define);
  98.     printf("#define %s\n", define);
  99.     printf("/*\n");
  100.     printf(fnfmt, outputname );
  101.     printf(rcsfmt, release); 
  102.     printf(rcsfmt, rcsid); 
  103.     printf(rcsfmt, rcsdate); 
  104.     printf(protosblurb, library);
  105.     printf(copyright); 
  106.     printf("*/\n");
  107.     printf("\n#ifndef %s\n#include \<%s\>\n#endif\n", 
  108.        libincludedefine, libincludename); 
  109.     printf("\n#ifndef %s\n#include \<%s\>\n#endif\n", 
  110.        libincludedefine1, libincludename1); 
  111.     printf("\n#ifndef %s\n#include \<%s\>\n#endif\n", 
  112.        libincludedefine2, libincludename2); 
  113.   } else if (what == "pragmas") {
  114.     pragmablurb="**\n**\tPragmas file for %s.library\n**\n";
  115.     printf("/*\n");
  116.     printf(fnfmt, pragmaname );
  117.     printf(rcsfmt, release); 
  118.     printf(rcsfmt, rcsid); 
  119.     printf(rcsfmt, rcsdate); 
  120.     printf(pragmablurb, library);
  121.     printf(copyright); 
  122.     printf("*/\n");
  123.   } else if (what == "fd") {
  124.     fdblurb="**\n**\tFD file for %s.library\n**\n";
  125.     printf("**\n");
  126.     printf(fnfmt, fds );
  127.     printf(rcsfmt, release); 
  128.     printf(rcsfmt, rcsid); 
  129.     printf(rcsfmt, rcsdate); 
  130.     printf(fdblurb, library);
  131.     printf(copyright); 
  132.     printf("**\n");
  133.     printf("##base _%s\n##bias 30\n##public\n", basename);
  134.   }
  135.   base = 30;
  136.   state = public;
  137.   next;
  138. }
  139.  
  140. state != 0 && $1 ~ libfunctype {
  141.   if (!match($0, /[A-Za-z][A-Za-z0-9_]*\(/)) {
  142.     printf("$0: No function name") >stderr;
  143.     exit 1;
  144.   }
  145.   fname = substr($0, RSTART, RLENGTH - 1);
  146.   sub(libprefix, "", fname);
  147.   rtype = substr($0, 1, RSTART - 1);
  148.   sub(/^[^     ]* */, "", rtype);
  149.  
  150.   registerless = rtype""fname"(";
  151.  
  152.   arglist = $0;
  153.  
  154.   argnames = ""; reglist = ""; twoline = 0;
  155.  
  156.   sub(/^[^(]*\(/, "", arglist); 
  157.   sub(/\)[^)]*$/, "", arglist); 
  158.  
  159.   argn = split(arglist, args, ",");
  160.  
  161.   if (argn != 1 || args[1] !~ "^void$") {
  162.     pragmacode = sprintf("%02X", argn);
  163.  
  164.     for (i = 1; i < argn + 1; i++) {
  165.       sub(/ */, "", args[i]);
  166.       apn = split(args[i], ap, "[ *]+");
  167.       if (match(ap[1], /^REG\(d[0-7]\)$/)) {
  168.     pragmacode = sprintf("%X%s", substr(ap[1], 6, 1), pragmacode);
  169.       } else if (match(ap[1], /^REG\(a[0-7]\)$/)) {
  170.     pragmacode = sprintf("%X%s", substr(ap[1], 6, 1) + 8, pragmacode);
  171.       } else {
  172.     printf("%s: argument %s has no register\n", fname, ap[apn]) > stderr;
  173.     exit 1;
  174.       }
  175.       
  176.       argnames=argnames""ap[apn];
  177.       reglist=reglist""substr(ap[1], 5, 2);
  178.       sub(/^REG\(..\) */, "", args[i]);
  179.       lastrl = registerless;
  180.       if (!twoline && length(registerless""args[i]) > 76) {
  181.     twoline = 1;
  182.     registerless=registerless"\n        ";
  183.       }
  184.       registerless = registerless""args[i]
  185.       if (i < argn) {
  186.     argnames = argnames", ";
  187.     reglist = reglist"/";
  188.     registerless = registerless", ";
  189.       }
  190.     }
  191.   } else {
  192.     registerless = registerless"void";
  193.     pragmacode = "00";
  194.   }
  195.  
  196.   if (what == "protos") {
  197.     printf("%s);\n", registerless);
  198.   } else if (what == "pragmas") {
  199.     printf("#pragma libcall %s %s %X %s\n", 
  200.        basename, fname, base, pragmacode);
  201.   } else if (what == "fd") {
  202.     printf("%s(%s)(%s)\n", fname, argnames, reglist);
  203.   }
  204.   base += 6;
  205.   next;
  206. }
  207.  
  208. state != 0 && $1 ~ /^\/\*$/ && $2 == "TAGCALL" {
  209.   sub(fname, $3, lastrl);
  210.   if (what == "protos") {
  211.     printf("%s ...);\n", lastrl);
  212.   } else if (what == "pragmas") {
  213.     printf("#pragma tagcall %s %s %X %s\n", 
  214.        basename, $3, base - 6, pragmacode);
  215.   }
  216.   next;
  217. }
  218.  
  219. state != 0 && $1 ~ /^\/\*$/ {
  220.   if (what == "protos") {
  221.     printf "%s\n", $0;
  222.   } else if (what == "pragmas") {
  223.     printf "%s\n", $0;
  224.   } else if (what == "fd") {
  225.     sub(/\/\*/, "*------", $0);
  226.     sub(/\*\//, "------*", $0);
  227.     print $0;
  228.   }
  229.   next;    
  230. }
  231.  
  232. state != 0 {
  233.   if (what == "protos") {
  234.     print $0;
  235.   }
  236. }
  237.  
  238. END {
  239.   if (what == "protos") {
  240.     printf("\n#endif /* %s */\n", define);
  241.   } else if (what == "fd") {
  242.     printf("##end\n")
  243.   } 
  244. }
  245.